package com.example.xm.controller;

import com.example.xm.entity.Geshou;
import com.example.xm.entity.Yinyue;
import com.example.xm.entity.vo.YinYueVo;
import com.example.xm.service.IGeshouService;
import com.example.xm.service.IYinyueService;
import com.example.xm.web.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/yinyue")
public class YinyueController {
    @Autowired
    IYinyueService iYinyueService;
    @GetMapping("/list")
    public Result list(Yinyue yinyue) {
        PageInfo<Yinyue> geshous = iYinyueService.selectList(yinyue);
        return Result.success(geshous);
    }
    @GetMapping("/getTuijian")
    public Result getTuijian(Integer uid) {
        List<Yinyue> list= iYinyueService.getTuijian(uid);
        return Result.success(list);
    }
    @PostMapping("/add")
    public Result add(@RequestBody Yinyue yinyue) {
        return Result.success(iYinyueService.add(yinyue));
    }
    @PostMapping("/edit")
    public Result edit(@RequestBody Yinyue yinyue) {
        return Result.success(iYinyueService.edit(yinyue));
    }
    @DeleteMapping("/delete/{ids}")
    public Result delete(@PathVariable String ids){
        String[] split = ids.split(",");
        int[] intArray = new int[split.length];
        for (int i = 0; i < split.length; i++) {
            intArray[i] = Integer.parseInt(split[i]);
        }
        iYinyueService.delete(intArray);
        return Result.success();
    }
    @GetMapping("/getDetail")
    public Result getDetail(Integer vid,Integer uid) {
      YinYueVo yinYueVo= iYinyueService.getDetail(vid,uid);
      return Result.success(yinYueVo);
    }
}
